package com.wu.project.admin.api;

import com.wu.project.admin.annotations.Authorization;
import com.wu.project.admin.annotations.Log;
import com.wu.project.admin.component.JsonResult;
import com.wu.project.admin.entity.*;
import com.wu.project.admin.property.Constants;
import com.wu.project.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xuan
 */
@RestController
public class UserApi {

    @Autowired
    UserService userService;

    @Authorization
    @Log(name = "获取用户列表", isOpen = true)
    @PostMapping(value = "/user/list", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult userList(@RequestBody UserQueryVO userQueryVO) {
        return userService.getUserList(userQueryVO);
    }

    @Authorization
    @Log(name = "获取工人列表", isOpen = true)
    @PostMapping(value = "/worker/list", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult workerList(@RequestBody WorkerQueryVO workerQueryVO) {
        return userService.getWorkerList(workerQueryVO);
    }

    @Authorization
    @Log(name = "新增用户")
    @PostMapping(value = "/addUser", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult addUser(@RequestBody UserFullDO userDTO) {
        return userService.addUser(userDTO);
    }

    @Authorization
    @Log(name = "更新用户信息")
    @PostMapping(value = "/updateUser", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult updateUser(@RequestBody UserFullDO userDTO) {
        return userService.updateUser(userDTO);
    }

    @Authorization
    @Log(name = "删除用户")
    @PostMapping(value = "/delUser", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult delUser(@RequestBody UserFullDO userDTO) {
        return userService.delUser(userDTO);
    }

    @Authorization
    @Log(name = "新增工人")
    @PostMapping(value = "/addWorker", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult addWorker(@RequestBody UserWorkerDO workerDTO) {
        return userService.addWorker(workerDTO);
    }

    @Authorization
    @Log(name = "更新工人信息")
    @PostMapping(value = "/updateWorker", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult updateWorker(@RequestBody UserWorkerDO workerDTO) {
        return userService.updateWorker(workerDTO);
    }

    @Authorization
    @Log(name = "删除工人")
    @PostMapping(value = "/delWorker", produces = Constants.APPLICATION_JSON_UTF8)
    public JsonResult delWorker(@RequestBody UserWorkerDO workerDTO) {
        return userService.delWorker(workerDTO);
    }

    @GetMapping("/userListSimple")
    public JsonResult queryUserList() {
        return userService.queryUserList();
    }
}
